package com.mspbots.web.utils;

import com.mspbots.api.page.OrderItem;
import org.springframework.data.domain.Sort;

import java.util.List;
import java.util.stream.Collectors;

/**
 * com.mspbots.web.utils.PageableUtils
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/9/5
 */
public class PageableUtils {

    public static List<Sort.Order> orders(List<OrderItem> orderItems) {
        return orderItems.parallelStream().map(orderItem -> {
            if (orderItem.isAsc()) {
                return Sort.Order.asc(orderItem.getColumn());
            }
            return Sort.Order.desc(orderItem.getColumn());
        }).collect(Collectors.toList());
    }
}
